// 让小球向右下运动，遇到边缘后反弹
var ball = document.querySelector('.ball');
var ballSpeedX = 5,
  ballSpeedY = 5;
var moveCount = 0;

var rect = ball.getBoundingClientRect();
var ballWidth = rect.right - rect.left;
var ballHeight = rect.bottom - rect.top;
var startLeft = rect.left;
var startTop = rect.top;

var maxLeft = document.documentElement.clientWidth - ballWidth;
var maxTop = document.documentElement.clientHeight - ballHeight;

function moveBall() {
  var curLeft = startLeft + moveCount * ballSpeedX;
  var curTop = startTop + moveCount * ballSpeedY;
  if (curLeft < 0 || curLeft > maxLeft) {
    curLeft=maxLeft 
  }
  ball.style.left = curLeft + 'px';
}

function start() {
  setInterval(() => {
    moveBall();
  }, 50);
}
